package com.mm.ai.controller;

import com.mm.ai.common.dto.ResponseEntity;
import com.mm.ai.service.CozeKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Set;

/**
 * @Author：tangnaichao
 * @Date：2024/10/19 9:23
 */
@RequestMapping("/botKnowledge")
@RestController
public class CozeKnowledgeController {
    @Autowired
    private CozeKnowledgeService cozeKnowledgeService;

    @PostMapping("/files")
    public ResponseEntity<String> uploadFiles(@RequestParam("file") MultipartFile files) {
        cozeKnowledgeService.createKnowledge(files);
        return ResponseEntity.ok();
    }

    @PostMapping("/updateknowledgeById")
    public ResponseEntity updateknowledgeById(@RequestParam(value = "documentId") Long documentId,
                                              @RequestParam(value = "documentName") String documentName) {
        cozeKnowledgeService.updateknowledgeById(documentId, documentName);
        return ResponseEntity.ok();
    }

    @PostMapping("/deleteByDocumentIdBatch")
    public ResponseEntity<String> deleteByDocumentIdBatch(@RequestBody Set<String> documentIds) {
        cozeKnowledgeService.deleteByDocumentIdBatch(documentIds);
        return ResponseEntity.ok();
    }

    @PostMapping("/selectListByKnowledgeBaseIdPage")
    public ResponseEntity<String> selectListByKnowledgeBaseIdPage(@RequestParam(value = "datesetId") Long datesetId,
                                                                  @RequestParam(value = "currentPage") Integer currentPage,
                                                                  @RequestParam(value = "pageSize") Integer pageSize) {
        return ResponseEntity.ok(cozeKnowledgeService.selectListByKnowledgeBaseIdPage(datesetId, currentPage, pageSize));
    }
}
